<?php


namespace app\api\controller;


use app\api\BaseController;
use think\App;
use think\facade\Db;

/**
 * 文章模块
 * Class Agent
 * @package app\api\controller
 */
class Article extends BaseController
{
    protected $setRetail;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = app('\app\api\model\Article');
        $this->user = app('\app\api\model\User');
    }
    //获取动态分类
    public function get_cates(){
          $levels=Db::name('article_cate')->order('sort asc')->where('pid',0)->where('delete_time',0)->column('id,title');
          return json(['code' => 200, 'msg' => '成功', 'data' => $levels]);
    }

    public function list(){
        $param = get_params();
        $pid=$param['pid']??0;
        $where = [];
        if (!empty($param['cate_id'])) {
            $where[] = ['a.cate_id', '=', $param['cate_id']];
        }
        $where[] = ['a.delete_time', '=', 0];
        if($pid){
            $where[]=['c.pid','=',$pid];
        }
        $where[]=['a.status','=',1];
        $news=$this->model->getArticleList($where, $param);
        return json(['code' => 200, 'msg' => '成功', 'data' => $news]);
    }

    public function article_detail(){
        $param = get_params();
        $id=$param['id']??0;
        $token=$param['token']??null;
        $news=$this->model->getArticleById($id,$token);
        return json(['code' => 200, 'msg' => '成功', 'data' => $news]);
    }


}